﻿using System;
using Caliburn.Micro;

namespace WPFSample1
{
  /// <summary>
  /// Implementation of the ILog interfaces using
  /// <see cref="Console"/>.
  /// </summary>
  public class ConsoleLogger : ILog
  {
    #region Constants

    private const string ErrorText = "ERROR";
    private const string WarnText = "WARN";
    private const string InfoText = "INFO";

    #endregion Constants

    #region Fields

    private readonly Type _type;

    #endregion Fields

    #region Constructors

    public ConsoleLogger(Type type)
    {
      _type = type;
    }

    #endregion Constructors

    #region Helper Methods

    private string CreateLogMessage(string format, params object[] args)
    {
      return string.Format("[{0}] {1}", DateTime.Now.ToString("o"), string.Format(format, args));
    }

    #endregion Helper Methods

    #region ILog Members

    /// <summary>
    /// Logs the exception.
    /// </summary>
    /// <param name="exception">The exception.</param>
    public void Error(Exception exception)
    {
      Console.WriteLine(CreateLogMessage(exception.ToString()), ErrorText);
    }

    /// <summary>
    /// Logs the message as info.
    /// </summary>
    /// <param name="format">A formatted message.</param><param name="args">Parameters to be injected into the formatted message.</param>
    public void Info(string format, params object[] args)
    {
      Console.WriteLine(CreateLogMessage(format, args), InfoText);
    }

    /// <summary>
    /// Logs the message as a warning.
    /// </summary>
    /// <param name="format">A formatted message.</param><param name="args">Parameters to be injected into the formatted message.</param>
    public void Warn(string format, params object[] args)
    {
      Console.WriteLine(CreateLogMessage(format, args), WarnText);
    }

    #endregion ILog Members
  }
}